Understanding the $this->runData Array in Batoi RAD Framework


Unlock the full potential of the Batoi RAD Framework by mastering its core array, $this->runData. This comprehensive guide covers all components like errorHandler, request, db, config, session, entity, data, and route, helping developers to build robust applications efficiently.

Introduction

The $this->runData array is the backbone of applications developed on the Batoi RAD Framework. This array contains vital information that is generated and modified during the execution of the application. It holds essential parameters and objects, such as database connections, request and session details, configurations, and more. As an integral part of the Batoi RAD Framework, it helps developers keep track of various application states and makes it easy to handle different layers of an application holistically.

Structure of $this->runData

Below is a breakdown of what each key-value pair in the $this->runData array represents:

errorHandler

This is an object that contains information about how to handle errors in your application. The errorHandler also integrates a logging utility through logger.

Example Usage:
$this->runData['errorHandler']->lastError = "An error occurred. Please try again later.";

request

Holds details about the incoming HTTP request. Provides request headers, method (GET, POST, etc.), IP address, and other important attributes.
headers: HTTP headers present in the request.
body: Body content of the request.
method: HTTP method (GET, POST, etc.)
And many more…

Example Usage:
$method = $this->runData['request']->method;

The list of parameters in the request object can be found in the table below:

Sl No Parameter Description
1 headers [Cookie], [Accept-Language],[Accept-Encoding], [Sec-Fetch-Site], [Accept]
2 method GET or POST etc.
3 timestamp
4 uri For example, if the link of the accessed resource is https://example.com/adminpanel/page/add, the value of $this->runData[‘request’]->uri is /adminpanel/page/add
5 ip
6 user_agent
7 referer
8 get Array of Get parameters
9 post Array of post parameters
10 csrf_token

db

This object encapsulates the Database connection and related functionalities.
dbh: Database handler object.

Example Usage:
$this->runData['db']->select('a_task', ['livestatus' => '1'], false);

In the above, a_task is the table name that holds the tasks, and the select query returns all active tasks (livestatus = 1).

The list of methods of the db object is given below:

Sl No Parameter Description
1 select($table, $where = [], $allFields = false, $order = [], $limit = null, $join = null, $group = null)
2 insert($table, $data)
3 update($table, $data, $where)
4 delete($table, $where)
5 query($sql, $params = [])
6 archive($table, $where)
7 activate($table, $where)
8 suspend($table, $where)

config

This array holds both system-level and application-level configurations.

sys: System-level configurations like project title, timezone, session settings, etc.
app: Application-level configurations like API keys.
dir: Directory structure that can be accessed within the application.

Example Usage:
$projectTitle = $this->runData['config']['sys']['project_title'];
$mailGunAPIKey = $this->runData['config']['app']['mailgun_api_key'];

In the above, you need to add mailgun_api_key into your config settings, whereas the system settings are already available, and you need to set up their values during the project setup, but you can edit later (make sure that the edit does not break the application).

The full list of other config‘s system (sys) parameters is in the table below:

Sl No Parameter Default Value Description
1 project_title
2 author
3 encryption_key Random
4 encryption_salt Random
5 base_url
6 theme_name
7 timezone America/New_York
8 locale en_US
9 currency USD
10 country US
11 session_name Random
12 session_lifetime 1800
13 session_path_default N
14 session_domain The domain name of the Site
15 session_secure 1 0 = No; 1 = Yes
16 session_httponly 1
17 session_idle_timeout 300
18 session_path
19 sso_role_id_default 2 The guest role is the default role_id
20 mfa_settings
21 display_errors true Mark it false for the production Site.
22 site_status L L = Live, U = Under Upgrade
23 ip_access_restrict N N = No; Y = Yes
24 site_update_pending N N = No; Y = Yes
25 update_items
26 enable_sql_log true
27 encryption_method AES-256-CBC

The directories that can be accessed within the application are listed below:

Sl No Parameter Description
1 site The base directory of the Site (installation of RAD); may be denoted by [site]
2 rad The RAD files that includes systems and application; [site]/rad
3 log [site]/rad/log
4 error
5 session [site]/rad/log/session
6 data [site]/rad/data
7 class_core [site]/rad/class/core
8 class_app [site]/rad/class/app
9 route [site]/rad/route
10 theme [site]/rad/theme/[theme_name]
11 sys [site]/rad/sys
12 vendor [site]/rad/vendor
13 www The folder or directory where the domain name is pointed to; e.g., it is [site]/rad/public_html in cPanel based servers.
14 pub [site]/rad/[www]/pub

session

An object that manages session data. Includes both system-level and application-level session configuration.

Example Usage:
$sessionLifetime = $this->runData['session']->config['sys']['session_lifetime'];

entity

An associative array that holds information about the logged-in user.

Example Usage:
$userId = $this->runData['entity']['id'];

The following is the list of parameters of the entity array:

Sl No Parameter Description
1 is_logged_in
2 id
3 uid
4 type U= User, A= API
5 username
6 fullname
7 email
8 mobile
9 agreement_signed Y = Yes, N = No. If the value is N; the user is redirected towards confirming the agreement before entering the login. The default value depends on the need of the application to enforce the consent of users to the agreement before using the application.
10 view_status render
11 view_render_scope full
12 view_redirect_url
13 role_type The type of role assigned to the user. non_saas for Non-SaaS users and saas for SaaS users.
14 role_id
15 spaces_roles Applicable only for SaaS users. An array indicating specific roles assigned to the user within different spaces. Each entry is a role-space mapping in the format space_id:role_id.
16 spaces Applicable only for SaaS users. An array of role IDs of a user for each SaaS spaces.
17 space_id Applicable only for SaaS users. An array of space IDs where the user is assigned, indicating the spaces the user is associated with.
18 route_access Applicable only for SaaS users. Indicates whether the user has access to specific routes or features within the application. Y = Yes, N = No.

data

Stores any additional data that may be used across the application. It's often used for passing values between different functionalities within the framework.

Example Usage:
$this->runData['data']['tasks'] = $taskList;

In the above, the task list is getting assigned to a new parameter in the data array called tasks.

route

Stores information about routing, including alert messages and metadata related to the current page.

Example Usage:
$pageTitle = $this->runData['route']['meta_title'];

The list of route parameters is given below:

Sl No Parameter Description
1 id
2 uid
3 access_scope private = Private route or URL; public = Public route or URL (the value is inherited from Microservice)
4 is_saas N= Non-SaaS route; Y = SaaS route (the value is inherited from Microservice)
5 access_role_ids This is an array of role_ids that stores the roles that can access this route. Please note that this has applicability only for private routes.
6 url The full URL; e.g,
https://example.com/adminpanel/page/add
7 path_full Path after the domain. For example, if the domain is https://example.com/adminpanel/page/add, the value of $this->runData[‘route][‘path_full’] is adminpanel/page/add
8 pathparts It’s an array; e.g., in the above example,
[0] = adminpanel
[1] = page
[2] = add
9 path This is path of the route in the Microservice; in the above example, it is page/add
10 assets_url The URL of publicly published assets like CSS, JS, images and any other files; e.g., https://example.com/assets/[theme_name]. Please note that this is a virtual link that gets asset files stored inside the respective theme folder.
11 alert_from_request The base directory of the Site (installation of RAD); may be denoted by [site]
12 alert The type of alert; info, warning, danger
13 alert_message Messages of alert
14 h1
15 meta_title
16 meta_description

ms(Microservice)

Contains the values of different parameters of the corresponding microservices of the route.

Sl No Parameter Description
1 id
2 uid
3 name For example, if the URL accessed is https://example.com/adminpanel/page/add, the value of name is adminpanel.
4 type
5 access_scope private = Private route or URL; public = Public route or URL (the value is inherited from Microservice).
6 is_saas N = Non-SaaS route; Y = SaaS route (the value is inherited from Microservice)
7 access_role_ids This is an array of role_ids that stores the roles that can access this route. Please note that this has applicability only for private routes.
8 default_route_id
9 tpl_name Default value is default

nav

Contains the navigation menu's structure. It can be multi-level; i.e, multiple menu sets can be stored. It holds metadata like menu titles, links, and access roles.

Example Usage:
$menuTitle = $this->runData[‘nav’][0][0][‘menu’]; // the title of the first menu title of first nav
$link = $this->runData[‘nav’][0][0][‘href’]; // the link of the first menu title of first nav
$roleIDs = explode(‘,’,$this->runData[‘nav’][0][0][‘roles’]); // the roles that can access the first menu of the first nav

Conclusion

Understanding $this->runData is crucial for effective development in the Batoi RAD Framework. Its comprehensive structure provides a clear roadmap to different functionalities and states within the application.